<template>
    <div class="list-container">
		
		<div class="detail">
			<el-row>
			  <el-col :span="12" class="card-box">
			    <el-card>
			      <div slot="header"><span>CPU</span></div>
			      <div class="el-table el-table--enable-row-hover el-table--medium">
			        <table cellspacing="0" style="width: 100%;">
			          <thead>
			            <tr>
			              <th class="is-leaf"><div class="cell">属性</div></th>
			              <th class="is-leaf"><div class="cell">值</div></th>
			            </tr>
			          </thead>
			          <tbody>
			            <tr>
			              <td><div class="cell">核心数</div></td>
			              <td><div class="cell" v-if="server.cpu">{{ server.cpu.cpuNum }}</div></td>
			            </tr>
			            <tr>
			              <td><div class="cell">用户使用率</div></td>
			              <td><div class="cell" v-if="server.cpu">{{ server.cpu.used }}%</div></td>
			            </tr>
			            <tr>
			              <td><div class="cell">系统使用率</div></td>
			              <td><div class="cell" v-if="server.cpu">{{ server.cpu.sys }}%</div></td>
			            </tr>
			            <tr>
			              <td><div class="cell">当前空闲率</div></td>
			              <td><div class="cell" v-if="server.cpu">{{ server.cpu.free }}%</div></td>
			            </tr>
			          </tbody>
			        </table>
			      </div>
			    </el-card>
			  </el-col>
			
			  <el-col :span="12" class="card-box">
			    <el-card>
			      <div slot="header"><span>内存</span></div>
			      <div class="el-table el-table--enable-row-hover el-table--medium">
			        <table cellspacing="0" style="width: 100%;">
			          <thead>
			            <tr>
			              <th class="is-leaf"><div class="cell">属性</div></th>
			              <th class="is-leaf"><div class="cell">内存</div></th>
			              <th class="is-leaf"><div class="cell">JVM</div></th>
			            </tr>
			          </thead>
			          <tbody>
			            <tr>
			              <td><div class="cell">总内存</div></td>
			              <td><div class="cell" v-if="server.mem">{{ server.mem.total }}G</div></td>
			              <td><div class="cell" v-if="server.jvm">{{ server.jvm.total }}M</div></td>
			            </tr>
			            <tr>
			              <td><div class="cell">已用内存</div></td>
			              <td><div class="cell" v-if="server.mem">{{ server.mem.used}}G</div></td>
			              <td><div class="cell" v-if="server.jvm">{{ server.jvm.used}}M</div></td>
			            </tr>
			            <tr>
			              <td><div class="cell">剩余内存</div></td>
			              <td><div class="cell" v-if="server.mem">{{ server.mem.free }}G</div></td>
			              <td><div class="cell" v-if="server.jvm">{{ server.jvm.free }}M</div></td>
			            </tr>
			            <tr>
			              <td><div class="cell">使用率</div></td>
			              <td><div class="cell" v-if="server.mem" :class="{'text-danger': server.mem.usage > 80}">{{ server.mem.usage }}%</div></td>
			              <td><div class="cell" v-if="server.jvm" :class="{'text-danger': server.jvm.usage > 80}">{{ server.jvm.usage }}%</div></td>
			            </tr>
			          </tbody>
			        </table>
			      </div>
			    </el-card>
			  </el-col>
			
			  <el-col :span="24" class="card-box">
			    <el-card>
			      <div slot="header">
			        <span>服务器信息</span>
			      </div>
			      <div class="el-table el-table--enable-row-hover el-table--medium">
			        <table cellspacing="0" style="width: 100%;">
			          <tbody>
			            <tr>
			              <td><div class="cell">服务器名称</div></td>
			              <td><div class="cell" v-if="server.sys">{{ server.sys.computerName }}</div></td>
			              <td><div class="cell">操作系统</div></td>
			              <td><div class="cell" v-if="server.sys">{{ server.sys.osName }}</div></td>
			            </tr>
			            <tr>
			              <td><div class="cell">服务器IP</div></td>
			              <td><div class="cell" v-if="server.sys">{{ server.sys.computerIp }}</div></td>
			              <td><div class="cell">系统架构</div></td>
			              <td><div class="cell" v-if="server.sys">{{ server.sys.osArch }}</div></td>
			            </tr>
			          </tbody>
			        </table>
			      </div>
			    </el-card>
			  </el-col>
			
			  <el-col :span="24" class="card-box">
			    <el-card>
			      <div slot="header">
			        <span>Java虚拟机信息</span>
			      </div>
			      <div class="el-table el-table--enable-row-hover el-table--medium">
			        <table cellspacing="0" style="width: 100%;">
			          <tbody>
			            <tr>
			              <td><div class="cell">Java名称</div></td>
			              <td><div class="cell" v-if="server.jvm">{{ server.jvm.name }}</div></td>
			              <td><div class="cell">Java版本</div></td>
			              <td><div class="cell" v-if="server.jvm">{{ server.jvm.version }}</div></td>
			            </tr>
			            <tr>
			              <td><div class="cell">启动时间</div></td>
			              <td><div class="cell" v-if="server.jvm">{{ server.jvm.startTime }}</div></td>
			              <td><div class="cell">运行时长</div></td>
			              <td><div class="cell" v-if="server.jvm">{{ server.jvm.runTime }}</div></td>
			            </tr>
			            <tr>
			              <td colspan="1"><div class="cell">安装路径</div></td>
			              <td colspan="3"><div class="cell" v-if="server.jvm">{{ server.jvm.home }}</div></td>
			            </tr>
			            <tr>
			              <td colspan="1"><div class="cell">项目路径</div></td>
			              <td colspan="3"><div class="cell" v-if="server.sys">{{ server.sys.userDir }}</div></td>
			            </tr>
			          </tbody>
			        </table>
			      </div>
			    </el-card>
			  </el-col>
			
			  <el-col :span="24" class="card-box">
			    <el-card>
			      <div slot="header">
			        <span>磁盘状态</span>
			      </div>
			      <div class="el-table el-table--enable-row-hover el-table--medium">
			        <table cellspacing="0" style="width: 100%;">
			          <thead>
			            <tr>
			              <th class="is-leaf"><div class="cell">盘符路径</div></th>
			              <th class="is-leaf"><div class="cell">文件系统</div></th>
			              <th class="is-leaf"><div class="cell">盘符类型</div></th>
			              <th class="is-leaf"><div class="cell">总大小</div></th>
			              <th class="is-leaf"><div class="cell">可用大小</div></th>
			              <th class="is-leaf"><div class="cell">已用大小</div></th>
			              <th class="is-leaf"><div class="cell">已用百分比</div></th>
			            </tr>
			          </thead>
			          <tbody v-if="server.sysFiles">
			            <tr v-for="(sysFile, index) in server.sysFiles" :key="index">
			              <td><div class="cell">{{ sysFile.dirName }}</div></td>
			              <td><div class="cell">{{ sysFile.sysTypeName }}</div></td>
			              <td><div class="cell">{{ sysFile.typeName }}</div></td>
			              <td><div class="cell">{{ sysFile.total }}</div></td>
			              <td><div class="cell">{{ sysFile.free }}</div></td>
			              <td><div class="cell">{{ sysFile.used }}</div></td>
			              <td><div class="cell" :class="{'text-danger': sysFile.usage > 80}">{{ sysFile.usage }}%</div></td>
			            </tr>
			          </tbody>
			        </table>
			      </div>
			    </el-card>
			  </el-col>
			</el-row>
    </div>
    </div>
</template>
<script>
	import NavCard from '@/components/nav-card/index.vue'
	import BreadCrumb from '@/components/bread-crumb/index.vue'
import { getServer } from "@/api/monitor/server";

export default {
  name: "Server",
  components: {
      NavCard,
      BreadCrumb
  },
  data() {
    return {
      // 服务器信息
      server: []
    };
  },
  created() {
    this.getList();
    this.openLoading();
  },
  methods: {
    /** 查询服务器信息 */
    getList() {
      getServer().then(response => {
        this.server = response.data;
        this.$modal.closeLoading();
      });
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载服务监控数据，请稍后！");
    }
  }
};
</script>
<style lang="scss" scoped>
.list-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: #F7F8FD;
}

.bread-crumb {
    margin-top: 21px;
    padding-left: 20px;
}

.title {
    font-size: 26px;
    color: #4B4B4B;
    font-weight: bold;
    margin: 0;
    margin-top: 18px;
    padding-left: 20px;
}

.detail {
    margin-top: 23px;
    margin-left: 20px;
    padding: 12px 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    border-radius: 5px;

    .search-input {
        width: 264px;
        height: 47px;
        background: #FFFFFF;
        border-radius: 5px;

        ::v-deep input {
            line-height: 45px;
            height: 47px;
            display: inline-block;
        }

        ::v-deep .el-input__icon {
            line-height: 45px;
            height: 45px;
            vertical-align: -0.15em;
            color: #4373F1;
        }
    }

    .table {
        flex: 1;
        background-color: #fff;
        margin: 13px 0 16px;

        ::v-deep .table-header-cell {
            background-color: #EBEFF8;
            padding-left: 21px;
            font-weight: 500;
            font-size: 16px;
            color: #414141;
        }
        .el-table {
            height: 100%;
        }
        ::v-deep .el-table__cell {
            padding-left: 21px;
            font-weight: 500;
            font-size: 16px;
            color: #414141;
        }
        :v-deep .el-table__body-wrapper {
            height: 100%;
        }
        :v-deep .el-table__empty-block {
            height: 100%;
        }
        .operation {
            display: flex;
            align-items: center;
            height: 100%;

            .view, .edit, .delete {
                cursor: pointer;
                font-weight: 500;
                font-size: 16px;
                color: #4373F1;
                height: 16px;
                line-height: 16px;
                background-repeat: no-repeat;
                background-position: 0 center;
                user-select: none;
            }
        }
    }
}

.edit-box {
    display: flex;
    flex-direction: column;
    align-items: center;

    ::v-deep .el-dialog__footer {
        display: none;
    }
    
    .row1 {
        display: flex;

        .el-select {
            margin-right: 7px;

            &:nth-last-child(1) {
                margin-right: 0;
            }
        }
    }

    .row2 {
        width: 100%;
        margin-top: 7px;

        .el-select {
            width: 100%;
        }
    }

    .submit {
        width: 164px;
        height: 56px;
        background: #4373F1;
        border-radius: 5px;
        user-select: none;
        line-height: 56px;
        color: #fff;
        text-align: center;
        margin-top: 22px;
        cursor: pointer;
    }
}
.edit-region {
    font-weight: 500;
    font-size: 16px;
    color: #4373F1;
    cursor: pointer;
}
::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 40vh !important;
}

.pagination-container{
    background: #f7f8fd;
    padding: 32px 16px;
}
</style>
